$(function(){
    topBottomTooler();


  $(window).scroll(function(){
    topBottomTooler();
  });
   $('[data-toggle="tooltip"]').tooltip();

   	//console.dir(parseInt($(window).scrollTop()));

});

function goToTop(){
	$(window).scrollTop(0);
}

function goToBottom(){
	$(window).scrollTop($('body').height());
}

//添加书籍到我的书架   添加书签
function addBookShelf(book_id,article_id){
    if(book_id > 0 || article_id > 0){
      $.ajax({
         type: "POST",
         url: addBookMark_url,
         data: "book_id="+book_id+'&article_id='+article_id,
         success: function(msg){
            if(msg == 'success'){
              swal({
                   title:"已成功添加到我的书架",
                   text:"",
                   type:"success"
               });
            }else if(msg == 'overlv'){
                swal("您已会员等级限制","请查看会员等级说明","error");
            }else if(msg == 'over'){
                swal("您已经添加过了","","error");
            }else{
              swal({
                   title:"网络不稳定，添加失败！",
                   text:"",
                   type:"error"
               });
            }
         }
      });
    }
}

//推荐投票
function tjArticle(book_id,article_id){
  if(book_id > 0){
      if(article_id < 0){
          var article_id = 0;
      }
      $.ajax({
         type: "POST",
         url: tjArticle_url,
         data: "book_id="+book_id+'&article_id='+article_id,
         success: function(msg){
            if(msg == 'success'){
              swal({
                   title:"我们已经记录了本次推荐",
                   text:"感谢您的参与!",
                   type:"success"
               });
            }else if(msg == 'overBook'){
                swal('每个章节每天只能推荐一次',"感谢您的参与！","error");
            }else if(msg == 'overNums'){
                swal('您已超过您会员等级的限制',"感谢您的参与！","error");
            }else{
                swal('网络不稳定，稍后再试',"","error");
            }
         }
      });
    }
}

function topBottomTooler(){
	var h = $('body').scrollTop();
	var wh = $(window).height();
	$('#top-bottom-tooler').css({"top":h+(wh/2)-100,"display":'block'});
}

function SetHome(obj){
    try{///IE
        obj.setHomePage(url);
    }catch(e){
      if(window.netscape){
            try{
             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }catch(e){
               swal({
                   title:"抱歉，此操作被浏览器拒绝！",
                   text:"请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'",
                   type:"error"
               });
               return false;
            }
      }else{
            swal({
               title:"抱歉，您所使用的浏览器无法完成此操作",
               text:"您需要手动将【"+url+"】设置为首页",
               type:"error"
            });
            return false;
      }
   }
   swal({title:"设置成功", text:"",type:"success"});
}

function AddFavorite(title) {
    try {
        window.external.addFavorite(url, title);
    }
  catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        }catch (e) {
           swal({
               title:"抱歉，您所使用的浏览器无法完成此操作",
               text:"加入收藏失败，请使用 Ctrl+D 进行添加",
               type:"error"
           });
           return false;
       }
    }
    swal({title:"收藏成功",text:"",type:"success"});
  }